﻿// console_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <fstream>  
#include <sstream>  
#include <string>
#include <iostream>
#include <format>

size_t write_file(const std::string& filename, const std::string& content) {  
    std::ofstream file;  
    file.open(filename, std::ios::app | std::ios::binary);  
    if (!file.is_open()) {  
        // dbgprint("codergege ERROR 打开文件失败 %s %d", __FUNCTION__, __LINE__);
        return 0;
    }  
    std::stringstream ss;  
    ss << content << std::endl;  
    std::string full_content = ss.str();  
    size_t bytes_written = full_content.length();  
    file.write(full_content.c_str(), bytes_written);  
    file.close();  
    return bytes_written;
}  

int main()
{
    auto filepath = "D:\\test_console.txt";
    for (int i = 0; i < 4; i++) {
		std::cout << "写入文件 " << i << std::endl;
        write_file(filepath, "11, 22, bb, cc");
    }
    std::cout << "写入完成" << std::endl;
}
